/**
 * 作者：伍祖清
 * 时间：2016-03-22 微信端
 * 描述：ajax统一请求和获取连接参数工具类
 */
var base = null;
window.app = {};
var cache = {};
//var server_host = 'https://wx.xinmailuo.com/phone/api/';
//var server_root = 'https://wx.xinmailuo.com';
var server_host = 'https://xindian.jmodata.com/phone/api/';
var server_root = 'https://xindian.jmodata.com';
var storege = window.localStorage;
var HISTORY = "app_history";
var TRANS_PARAM = "tans_param";
base = base || {
	/**
	 * URL管理
	 */
	url: {
		userLogin : server_host + 'userLogin',//用户登录
		getHomePageData : server_host + 'getHomePageData',//获取菜单信息
		getTweetsContent : server_host + 'getTweetsContent',//获取推文内容
		getMyLableList : server_host + 'getMyLableList',//获取个人标签
		familiarCustomerList : server_host + 'familiarCustomerList',//熟悉客户列表
		completeCustomerInfo : server_host + 'completeCustomerInfo',//补全客户信息
		deleteAtrticleInfo : server_host + 'deleteAtrticleInfo',//删除推文
		articleDataInfo : server_host + 'articleDataInfo',//获取文章信息
		getCustomerImpact : server_host + 'getCustomerImpact',//脉络客户影响力
		getShareCustomer : server_host + 'getShareCustomer',//脉络转发客户
		getDiamondCustomers: server_host + 'getDiamondCustomers',//脉络潜在客户
		getCustomerInfo : server_host + 'getCustomerInfo', //获取客户信息
		getEmployeeList: server_host + 'getEmployeeList', //获取员工列表
		getDepartList: server_host + 'getDepartList', //获取部门列表
		searchCustomerInfo: server_host + 'searchCustomerInfo',//客户全局搜索
		getAllTask: server_host + 'getAllTask',//获取所有任务
		uploadFile: server_host + 'uploadFile',//文件上传
		customerInfo: server_host + 'customerInfo',//客户详情
		customerReadInfo: server_host + 'customerReadInfo',//阅读信息
		getCardList: server_host + 'getCardList',//获取名片插件列表
		getEnrollList: server_host + 'getEnrollList',//获取报名插件列表
		lableList: server_host + 'lableList',//获取公司全部标签
		teamDataStatistics: server_host + 'teamDataStatistics',//数据统计（团队统计）
		employsDataStatistics: server_host + 'employsDataStatistics',//数据统计（员工影响力）
		customerDataStatistics: server_host + 'customerDataStatistics',//数据统计（客户影响力）
		articleStatistics: server_host + 'articleStatistics',//数据统计（推文统计）
		customerArticleStatistics: server_host + 'customerArticleStatistics',//数据统计（客户推文统计）
		updateArticleInfo: server_host + 'updateArticleInfo',//保存(修改)推文
		getArticleInfo: server_host + 'getArticleInfo',//获取推文详情
		getEnrollInfo: server_host + 'getEnrollInfo',//获取客户报名详情（单个客户）
		updatePassword: server_host + 'updatePassword',//密码修改
		companyPaySet: server_host + 'companyPaySet',//获取公司设置（支付）
		companyWeChatSet: server_host + 'companyWeChatSet',//获取公司设置（公众号）
		addCompanyWeChat: server_host + 'addCompanyWeChat',//公司设置（公众号绑定）
		addCompanyPay: server_host + 'addCompanyPay',//公司设置（商户号绑定）
		getDepartListAndEmployeeList: server_host + 'getDepartListAndEmployeeList',//获取部门及部门下所有员工
		addDistributionTask: server_host + 'addDistributionTask',//分配任务
		addLable: server_host + 'addLable',//添加标签
		edtLable: server_host + 'edtLable',//修改标签
		getArticleContentLibrary: server_host + 'getArticleContentLibrary',//内容库管理推文
		operationContentLibrary: server_host + 'operationContentLibrary',//移入移除内容库
		getArticleDataInfo: server_host + 'getArticleDataInfo',//内容库文章数据信息
		exportArticleDataInfo: server_host + 'exportArticleDataInfo',//内容库文章数据信息导出表格
		deleteCardInfo: server_host + 'deleteCardInfo',//删除名片信息
		addCardInfo: server_host + 'addCardInfo',//添加（修改）名片信息
		getCardInfo: server_host + 'getCardInfo',//获取名片详情
		getEnrollList: server_host + 'getEnrollList',//获取报名插件列表
		addEnrollInfo: server_host + 'addEnrollInfo',//添加（修改）报名插件信息
		deleteEnrollInfo: server_host + 'deleteEnrollInfo',//删除报名插件信息
		getContentList: server_host + 'getContentList',//获取内容库
		getContentLibraryArticleInfo: server_host + 'getContentLibraryArticleInfo',//用户获取内容库文章
		myDistributionTask: server_host + 'myDistributionTask',//我分配的任务
		myReceiveTask: server_host + 'myReceiveTask',//我接收的任务
		deleteTask: server_host + 'deleteTask',//删除任务
		taskInfo: server_host + 'taskInfo',//任务详情
		exportTaskInfo: server_host + 'exportTaskInfo',//任务详情导出表格
		taskStop: server_host + 'taskStop',//中止任务
		shareTask: server_host + 'shareTask',//分享任务
		feedbackTask: server_host + 'feedbackTask',//反馈任务
		getEmployList: server_host + 'getEmployList',//部门员工列表
		addUser: server_host + 'addUser',//添加员工
		addDepart: server_host + 'addDepart',//添加部门
		edtStaffPassword: server_host + 'edtStaffPassword',//重置密码
		deleteSection: server_host + 'deleteSection',//删除部门
		delStaff: server_host + 'delStaff',//删除员工
		getEnrollInfoList: server_host + 'getEnrollInfoList',//获取客户报名详情（某篇文章）
		exportEnrollInfo: server_host + 'exportEnrollInfo',//获取客户报名详情(某篇文章)导出表格
		addPersonalRedPack: server_host + 'addPersonalRedPack',//发送个人红包
		addCustomerEnroll: server_host + 'addCustomerEnroll',//添加客户报名
		sendVerificationCode: server_host + 'sendVerificationCode',//发送验证码
		forgotPassword: server_host + 'forgotPassword',//忘记密码
		updateReadInfo: server_host + 'updateReadInfo',//修改阅读时长
		addCardCustomerInfo: server_host + 'addCardCustomerInfo',//点击名片上的电话或者微信
		addLikeInfo: server_host + 'addLikeInfo',//文章点赞
		cancelLikeInfo: server_host + 'cancelLikeInfo',//文章取消点赞
		wxConfig : server_root + '/phone/wx/wxConfig.do',//微信初始化数据
		getRedPackList: server_host + 'getRedPackList',//红包加持列表
		getArticleList: server_host + 'getArticleList',//红包推文（我的推文和我的任务）
		addShareInfo: server_host + 'addShareInfo',//添加分享记录
		relationMap : server_host + 'relationMap',//获取脉络图数据
		addRedPack: server_host + 'addRedPack',//添加红包加持
		getWeCharArticle: server_host + 'getWeCharArticle',//微信文库
		getCustomerImpressionList: server_host + 'getCustomerImpressionList',//获取客户印象列表
		updateCustomerImpression: server_host + 'updateCustomerImpression',//添加/修改客户印象
		delCustomerImpression: server_host + 'delCustomerImpression',//删除客户印象
		getRedPackDraftInfo: server_host + 'getRedPackDraftInfo',//红包草稿箱列表
		getRedPackInfo: server_host + 'getRedPackInfo',//获取红包详情
		updateCustomerInfo: server_host + 'updateCustomerInfo',//微信提交经纬度
		editorRedPackStatus: server_host + 'editorRedPackStatus',//修改红包加持状态
		deleteRedPackDraft: server_host + 'deleteRedPackDraft',//删除红包草稿箱
		fileUpload: server_host + 'fileUpload',//上传支付的相关文件
		addArticleAnalyseInfo: server_host + 'addArticleAnalyseInfo',//存入选中文章
		getArticleAnalyseInfo: server_host + 'getArticleAnalyseInfo',//获取选中文章列表
		delArticleAnalyseInfo: server_host + 'delArticleAnalyseInfo',//删除选中文章列表
		getAnalyseInfo: server_host + 'getAnalyseInfo',//获取深度分析客户
		getAnalyseArticleInfo: server_host + 'getAnalyseArticleInfo',//获取深度分析文章
		getRedPackAmount: server_host + 'getRedPackAmount',//获取红包发放金额
		getGrantRedPackInfo: server_host + 'getGrantRedPackInfo',//获取红包明细
		addRedPackRenew: server_host + 'addRedPackRenew',//红包续费
		hierarchyCustomerInfo: server_host + 'hierarchyCustomerInfo',//获取层级用户
		addTickets: server_root + '/mw.ticket/api/addTickets',//添加门票
		getTicketsList: server_root + '/mw.ticket/api/getTicketsList',//获取门票
		deleteTickets: server_root + '/mw.ticket/api/deleteTickets',//删除门票
		getTicketsById: server_root + '/mw.ticket/api/getTicketsById',//根据门票ID获取门票
		addActivity: server_root + '/mw.ticket/api/addActivity',//添加活动
		getActivityList: server_root + '/mw.ticket/api/getActivityList',//获取活动
		deleteActivity: server_root + '/mw.ticket/api/deleteActivity',//删除活动
		getActivityById: server_root + '/mw.ticket/api/getActivityById',//根据活动ID获取活动
		getTicketsDetails: server_root + '/mw.ticket/api/getTicketsDetails',//查看门票领取详情
		receiveTickets: server_root + '/mw.ticket/api/receiveTickets',//领取门票前绑定相关数据
		showMyActivity: server_root + '/mw.ticket/api/showMyActivity',//查看活动
		checkQrCode: server_root + '/mw.ticket/api/checkQrCode',//生成商家检票二维码
		showMyTickets: server_root + '/mw.ticket/api/showMyTickets',//查看门票
		getMerchantInfo: server_host + 'getMerchantInfo',//获取商户信息
		addRechargeOrder: server_host + 'addRechargeOrder',//生成支付二维码
		getMerchantRecord: server_host + 'getMerchantRecord',//获取商户充值记录
		exportGrantRedPackInfo: server_host + 'exportGrantRedPackInfo',//红包明细导出表格
		customerArticleInfo: server_host + 'customerArticleInfo',//用户文章详情
		getDepartAndEmployeeList: server_host + 'getDepartAndEmployeeList',//获取部门及员工列表
		addGoods: server_host + 'addGoods',//添加商品接口
		getGoodsList: server_host + 'getGoodsList',//获取商品列表
		getOneGoods: server_host + 'getOneGoods',//获取单个商品
		delGoods: server_host + 'delGoods',//删除商品
		getAddress: server_host + 'getAddress',//获取客户地址
		addGoodsOrderSpec: server_host + 'addGoodsOrderSpec',//用户下单
		perpay: server_host + 'perpay',//微信预支付
		wxGetGoodsOrderSpecList: server_host + 'wxGetGoodsOrderSpecList',//微信获取订单
		delGoodsOrder: server_host + 'delGoodsOrder',//删除订单
		getGoodsOrderSpecListByGoodsId: server_host + 'getGoodsOrderSpecListByGoodsId',//获取商品订单列表
		exportGoodsOrderInfo: server_host + 'exportGoodsOrderInfo',//导出订单列表
		addVouchers: server_host + 'addVouchers',//添加/修改代金券
		delVouchers: server_host + 'delVouchers',//删除代金券
		getVouchersList: server_host + 'getVouchersList',//获取全部代金券信息
		getVouchersById: server_host + 'getVouchersById',//获取单个代金券信息
		addDiscountCoupons: server_host + 'addDiscountCoupons',//添加/修改打折券
		delDiscountCoupons: server_host + 'delDiscountCoupons',//删除打折券
		getDiscountCouponsList: server_host + 'getDiscountCouponsList',//获取全部打折券信息
		getDiscountCouponsById: server_host + 'getDiscountCouponsById',//获取单个打折券信息
		getTweetsAnalyseContent: server_host + 'getTweetsAnalyseContent',//获取深度分析文章
		addUserVouchers: server_host + 'addUserVouchers',//领取券
		getMyUserVouchers: server_host + 'getMyUserVouchers',//获取我的券(未使用过的)
		chinaMap: server_host + 'chinaMap',//中国地图统计
		sexMap: server_host + 'sexMap',//性别数据统计
		getLableNum: server_host + 'getLableNum',//标签数据统计
		getVouchersAndDiscountCoupons: server_host + 'getVouchersAndDiscountCoupons',//获取代金券和打折券
		totalArticleStatistics: server_host + 'totalArticleStatistics',//总文章统计
		articleStatisticsList:server_host + 'articleStatisticsList',//文章统计列表
		articleStatisticsOne:server_host + 'articleStatisticsOne',//获取单篇统计详情
		incomeLogList:server_host + 'incomeLogList',//获取收益列表
		getPoster:server_host + 'getPoster',//获取我的海报
		addGoodsOrderSpecLogistics:server_host + 'addGoodsOrderSpecLogistics',//添加发货物流
		addShareRead:server_host + 'addShareRead',//添加转发阅读人数 
		getElectricityList: server_host + 'getElectricityList',//获取商城列表
		testRead: server_host + 'testRead',//测试阅读
		getByOpenId: server_host + 'getByOpenId', //通过openid获取用户信息
		addTransferPerpay: server_host + 'addTransferPerpay',//输入金额得预支付
		getContentActivityList: server_host + 'getContentActivityList',//获取活动列表
		mailuoLogin: server_root + '/wlyAdmin/manager/mailuoLogin',//后台登录
		bindingMerchant: server_host + 'bindingMerchant',//绑定商户手机号
		totalMerchantPrice: server_host + 'totalMerchantPrice',//统计商户收益
		getUserVouchersByContentsId: server_host + 'getUserVouchersByContentsId',//查询领取代金券打折券列表
		exportUserVouchers: server_host + 'exportUserVouchers',//导出领取代金券打折券列表
	},
	/**
	 * ajax请求
	 * @param {Object} url请求连接
	 * @param {Object} data请求参数
	 * @param {Object} callback回调函数
	 */
	postData : function(url, data, callback) {
		console.log(url+"?"+JSON.stringify(data));
		$.ajax({  
            type: "post", //HTTP请求类型 
            url: url,  
            data: data,  
            dataType: 'json', //服务器返回json格式数据
            timeout:20000,//超时时间设置为20秒；
            success: function (data) {
            		console.log(data);
            		callback(data);
            }, //服务器返回响应
            error: function (xhr,type,errorThrown) {  
                //异常处理；
				console.log(type);
				if(this.spinner != null && this.spinner != ''){
					base.clearWait();
				}
//				mui.toast("请求出错！");  
            }  
        });
	},
	/**
	 * 获取URL链接参数，在通过URL跳转页面时，可通过此方法获取URL的参数
	 * @param {Object} val要获取的参数名称
	 */
	getParameter : function(val){
		var uri = window.location.search;
		var re = new RegExp("" + val + "=([^&?]*)", "ig");
		var str = ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : "");
		return decodeURIComponent(str);
	},
	getSavedData: function() {
		var history = JSON.parse(storege[HISTORY] || '[]');
		var item = history[history.length - 1];
		if (!item) {
			console.log('save:', {});
			return {};
		}
		var path = window.location.pathname;
		if (item.path == path) {
			history.pop();
			storege[HISTORY] = JSON.stringify(history);
			scrollTop = item.scrollTop;
			this.from = item.from;
			this.isBack = true;
			console.log('save:', item.saved || {});
			return item.saved || {};
		} else {
			this.from = item.path;
			this.isBack = false;
			console.log('save:', item.saved || {});
			return {};
		}
	},
	showView: function(url, param, saved, getScrollTop) {
		scrollTop = undefined;
		var history = JSON.parse(storege[HISTORY] || '[]');
		history.push({
			href: window.location.href,
			path: window.location.pathname,
			saved: saved,
			scrollTop: getScrollTop ? getScrollTop() : $(document.body).scrollTop(),
			from: getAbsolutePath(url, window.location.pathname),
		});
		storege[HISTORY] = JSON.stringify(history);
		storege[TRANS_PARAM] = JSON.stringify(param||{});
		window.location.href = url;
	},
	/**
	 * 设置等待加载
	 * @param {Object} text
	 */
	setWait: function(text) {
        var opts = {
            lines: 12, // 花瓣数目
            length: 10, // 花瓣长度
            width: 3, // 花瓣宽度
            radius: 10, // 花瓣距中心半径
            corners: 1, // 花瓣圆滑度 (0-1)
            rotate: 0, // 花瓣旋转角度
            direction: 1, // 花瓣旋转方向 1: 顺时针, -1: 逆时针
            color: '#FBDC9F', // 花瓣颜色
            speed: 1, // 花瓣旋转速度
            trail: 60, // 花瓣旋转时的拖影(百分比)
            shadow: false, // 花瓣是否显示阴影
            hwaccel: false, //spinner 是否启用硬件加速及高速旋转
            className: 'spinner', // spinner css 样式名称
            zIndex: 2e9, // spinner的z轴 (默认是2000000000)
    //      top: 'auto', // spinner 相对父容器Top定位 单位 px
    //      left: 'auto'// spinner 相对父容器Left定位 单位 px
        };
    	this.spinner = new Spinner(opts);
        $(document.body).append('<div id="mask_container"><div class="modal-backdrop"></div><div class="spinner-text-container">'+text+'</div></div>');
    	this.spinner.spin(document.body);//打开等待加载
    },
    clearWait: function() {
        $("#mask_container").remove();
        if (this.spinner != null) {
        	this.spinner.spin();//关闭等待加载	
        }
        this.spinner = null;
    },
    /**
	 * 是否是微信浏览器
	 */
	isOnWx: function() {
		var ua = window.navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            return true;
        } else {
            return false;
        }
	},
    /**
	 * 初始化配置
	 * @param onReady 初始化成功后的回调
	 */
	initWX: function(companyID,onReady) {
		//避免重复调用
		if(cache.wxInited) {
			return;
		}
		cache.wxInited = true;

		if(!base.isOnWx()) {
			console.info("please debug this page on weixin browser.");
			return;
		}
		
//		var url = encodeURIComponent(location.href);
		var url = window.location.href;
		base.postData(base.url.wxConfig,{companyID:companyID, url: url},function(res){
			var data = res.context;
			wx.config({
				debug: false,
				appId : data.appId,
				timestamp: data.timestamp, //生成签名的时间戳
				nonceStr: data.nonceStr, //生成签名的随机串
				signature: data.signature,//签名
				jsApiList: ['getLocation', 'openLocation', 'chooseWXPay', 'chooseImage', 'previewImage', 'uploadImage','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone','closeWindow'] //需要使用的JS接口列表
			});
		});

		wx.ready(function(){
			//mui.toast("微信初始化成功！");
			if(onReady != null) {
				onReady();
			}
		});

		wx.error(function(res){
			mui.toast("微信初始化失败！");
		});
	},
	/**
	 * 统一绑定分享按钮事件
	 */
	bindShare: function(shareData) {
		shareData.success = shareData.success|| function () { // 用户确认分享后执行的回调函数
			//do noting
			mui.toast('success');
		},
		shareData.cancel = shareData.cancel||function () { // 用户取消分享后执行的回调函数
			//do noting
			mui.toast('cancel');
		}
		wx.onMenuShareTimeline(shareData);//朋友圈
		wx.onMenuShareAppMessage(shareData);//微信好友
		wx.onMenuShareQQ(shareData);//qq
		wx.onMenuShareWeibo(shareData);//微博
		wx.onMenuShareQZone(shareData);//qq空间
		 
		//隐藏一些没什么用的按钮		
 

	},
	/**
	 * 微信支付
	 */
	weChatPay: function(data, onSuccess, onCancel, onFail) {
		if(!base.isOnWx()) {
			mui.toast("请在微信端调用此功能");
			return;
		}
		base.setWait('正在加载...');
		base.postData(base.url.perpay, data, function(data){//下微信预付单
			if (data.success) {
				var cfg = data.context;
				//weui.dialog(JSON.stringify(cfg));
				wx.chooseWXPay({
					timestamp: cfg.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
					nonceStr: cfg.nonceStr, // 支付签名随机串，不长于 32 位
					package: cfg.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
					signType: cfg.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
					paySign: cfg.paySign, // 支付签名
					success: function (res) {
						base.clearWait();
						if(onSuccess) {
							onSuccess(res);
						}
					},
					cancel: function(res) {
						base.clearWait();
						//mui.toast("支付被取消");
						if(onCancel) {
							onCancel();
						}
					},
					fail: function(res, arg2) {
						base.clearWait();
						mui.toast("对不起，支付失败:"+JSON.stringify(res)+","+JSON.stringify(arg2));
						if(onFail) {
							onFail();
						}
					}
				});
			}else{
				base.clearWait();
				mui.toast(data.msg);
			}
		});
	},
	/**
	 * 输入金额直接支付
	 * @param {Object} data
	 * @param {Object} onSuccess
	 * @param {Object} onCancel
	 * @param {Object} onFail
	 */
	weChatTransferPay: function(data, onSuccess, onCancel, onFail) {
		if(!base.isOnWx()) {
			mui.toast("请在微信端调用此功能");
			return;
		}
		base.setWait('正在加载...');
		base.postData(base.url.addTransferPerpay, data, function(data){//下微信预付单
			if (data.success) {
				var cfg = data.context;
				//weui.dialog(JSON.stringify(cfg));
				wx.chooseWXPay({
					timestamp: cfg.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
					nonceStr: cfg.nonceStr, // 支付签名随机串，不长于 32 位
					package: cfg.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
					signType: cfg.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
					paySign: cfg.paySign, // 支付签名
					success: function (res) {
						base.clearWait();
						if(onSuccess) {
							onSuccess(res);
						}
					},
					cancel: function(res) {
						base.clearWait();
						//mui.toast("支付被取消");
						if(onCancel) {
							onCancel();
						}
					},
					fail: function(res, arg2) {
						base.clearWait();
						mui.toast("对不起，支付失败:"+JSON.stringify(res)+","+JSON.stringify(arg2));
						if(onFail) {
							onFail();
						}
					}
				});
			}else{
				base.clearWait();
				mui.toast(data.msg);
			}
		});
	},
	getNowFormatToday : function(){
		var date = new Date();
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 0 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    var currentdate = date.getFullYear() + "-" + month + "-" + strDate;
	    return currentdate;
	}
    
}

app.global = (function() {
	var ls = window.localStorage;
	var GLOBAL = "app_global";
	var global = {
		set: function(key, data) {
			var global = JSON.parse(ls[GLOBAL] || '{}');
			global[key] = data;
			ls[GLOBAL] = JSON.stringify(global);
		},
		add: function(key, data) {
			var global = JSON.parse(ls[GLOBAL] || '{}');
			global[key].push(data);
			ls[GLOBAL] = JSON.stringify(global);
		},
		get: function(key) {
			var global = JSON.parse(ls[GLOBAL] || '{}');
			return global[key];
		},
		getOnce: function(key) {
			var global = JSON.parse(ls[GLOBAL] || '{}');
			var ret = global[key];
			if (ret != null) {
				delete global[key];
			}
			ls[GLOBAL] = JSON.stringify(global);
			return ret;
		},
		clear: function(key) {
			var global = JSON.parse(ls[GLOBAL] || '{}');
			delete global[key];
			ls[GLOBAL] = JSON.stringify(global);
		}
	};
//	console.log('global:', ls[GLOBAL]);
	return global;
})();

function getAbsolutePath(from, path) {
	if (from[0] === '/') {
		return from;
	}
	var parr = path.split('/').slice(0, -1);
	var farr = from.split('/');
	for (var i in farr) {
		var item = farr[i];
		if (item === '.') {
			continue;
		} else if (item === '..') {
			parr.pop();
		} else {
			parr.push(item);
		}
	}
	return parr.join('/');
}
